const { Categorys } = require("./apiModels/productCategory");
// const { APIError } = require("../rest");

module.exports = {
  "GET /api/product/category/query": async (ctx, next) => {
    let query = ctx.query;
    let p = await Categorys.queryList(query);
    ctx.rest(p);
  },

  "POST /api/product/category/create": async (ctx, next) => {
    let reqBody = ctx.request.body;
    var p = await Categorys.create(reqBody);
    ctx.rest(p, { message: "类别添加成功" });
  },

  "GET /api/product/category/delete/:id": async (ctx, next) => {
    // console.log(`delete product ${ctx.params.id}...`);
    var p = await Categorys.delete(ctx.params.id);
    ctx.rest(p, { message: "类别删除成功" });
  },

  "POST /api/product/category/update": async (ctx, next) => {
    let reqBody = ctx.request.body;
    var p = await Categorys.update(reqBody);
    ctx.rest(p, { message: "类别更新成功" });
  },

  "GET /api/product/category/detail/:id": async (ctx, next) => {
    console.log(`delete product ${ctx.params.id}...`);
    var p = await Categorys.detail(ctx.params.id);
    ctx.rest(p);
  },
};
